<?php

session_start();
include "../database.php";
//Posting new post to the wall
if (isset($_POST['new_post'])) {
    $author_id = $_SESSION['id'];
    $query = "SELECT current_project FROM user WHERE id = '$author_id'";
    $project_id = mysql_fetch_array(executeQuery($query))[0];
    //nl2br() -> replace new lines with <br />
    $content = nl2br($_POST['new_post']);

    //INSERT POST IN SQL
    $query = "INSERT INTO wall_posts (author_id, project_id, content) VALUES ('$author_id', '$project_id', '$content')";
    executeQuery($query);

    header("Location: ../project_wall.php");
}
//Deleting post with id
else if (isset($_GET['delete_post_id'])) {
    $post_id = $_GET['delete_post_id'];
    $query = "DELETE FROM wall_posts WHERE post_id = '$post_id'";
    executeQueryRowsAffected($query);
    
    $queryComment = "DELETE FROM commentary WHERE commentary_post_id = '$post_id'";
    executeQueryRowsAffected($queryComment);
}
?>
